<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	</head>

	<body>
		<input type="file" onchange="run(this)" />
		<textarea id="base64" style="width: 500px;height: 500px"></textarea>
		<script type="text/javascript">
			function run(input_file) {
				var file = input_file.files[0];
				if (!/image\/\w+/.test(file.type)) {
					alert("请确保文件为图像类型");
					return false;
				}
				var reader = new FileReader();
				reader.onload = function() {
					document.querySelector("#base64").value = this.result
				}
				reader.readAsDataURL(file);
			}
		</script>
	</body>

</html>
